import 'package:flutter/material.dart';

import '../common/common.dart';

class DefaultFormField extends StatelessWidget {
  final FocusNode? focusNode;
  final TextEditingController? textEditingController;
  final int? minLines;
  final int? maxLength;
  final int? maxLines;
  final double scrollPadding;
  final String? msg;
  final String? labelText;
  final String? hintText;
  final String? counterText;
  final TextStyle? style;
  final TextInputAction? textInputAction;
  final TextStyle? hintStyle;
  final bool obscureText;
  final String? errorText;
  final Function(String)? onChange;
  final Function()? onEditingComplete;
  final Widget? icon;
  final Widget? prefixIcon;
  final Widget? suffixIcon;
  final EdgeInsets? contentPadding;
  final bool isCollapsed;
  final InputBorder? border;
  final bool autoFocus;
  const DefaultFormField({
    super.key,
    this.focusNode,
    this.textEditingController,
    this.minLines = 1,
    this.maxLength,
    this.maxLines = 1,
    this.scrollPadding = 0,
    this.msg = '',
    this.errorText = '',
    this.labelText,
    this.textInputAction,
    this.style,
    this.hintStyle,
    this.obscureText = false,
    this.onChange,
    this.icon,
    this.prefixIcon,
    this.suffixIcon,
    this.counterText,
    this.onEditingComplete,
    this.contentPadding,
    this.isCollapsed = false,
    this.border,
    this.hintText,
    this.autoFocus = false,
  });

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      autofocus: autoFocus,
      focusNode: focusNode,
      style: style,
      controller: textEditingController,
      minLines: minLines,
      maxLength: maxLength,
      maxLines: maxLines,
      obscureText: obscureText,
      textInputAction: textInputAction,
      decoration: InputDecoration(
        icon: icon,
        prefixIcon: prefixIcon,
        suffixIcon: suffixIcon,
        iconColor: Styles.mainThemeColor,
        prefixIconColor: Styles.mainThemeColor,
        suffixIconColor: Styles.mainThemeColor,
        counterText: counterText,
        labelText: labelText,
        hintText: hintText,
        hintStyle:
            hintStyle ?? style?.copyWith(color: Styles.textTranslucentColor),
        filled: true,
        fillColor: Styles.lightColor,
        border: border ?? defaultBorder(),
        enabledBorder: border ?? enabledBorder(),
        focusedBorder: border ?? focusedBorder(),
        contentPadding: contentPadding,
        isCollapsed: isCollapsed,
      ),
      scrollPadding: EdgeInsets.only(bottom: scrollPadding),
      onChanged: onChange,
      onEditingComplete: onEditingComplete,
    );
  }
}

InputBorder defaultBorder() {
  return const OutlineInputBorder(
    borderSide: BorderSide(
      width: 1,
      color: Styles.mainThemeColor,
    ),
    borderRadius: BorderRadius.all(Radius.circular(8)),
  );
}

InputBorder enabledBorder() {
  return const OutlineInputBorder(
    borderSide: BorderSide(
      width: 1,
      color: Colors.grey,
    ),
    borderRadius: BorderRadius.all(Radius.circular(8)),
  );
}

InputBorder focusedBorder() {
  return const OutlineInputBorder(
    borderSide: BorderSide(
      width: 2,
      color: Styles.mainThemeColor,
    ),
    borderRadius: BorderRadius.all(Radius.circular(8)),
  );
}
